package org.wddsicmd.widgets;
 
import org.wddsicmd.app.ButtonTabComponent;
import org.wddsicmd.util.ResourceBundleUtil;
import org.wddsicmd.util.Log;
import org.wddsicmd.util.Resource;

import java.lang.Object;

import java.io.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import java.util.*;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;

import java.awt.*;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.Insets;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.Image;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.Timer;
import javax.swing.JTable;
import javax.swing.table.*;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeModelListener;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.Document;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;

import javax.swing.Icon;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
import javax.swing.plaf.basic.BasicGraphicsUtils;

public class TextFieldGroup extends JPanel {
       private final static String TAG = "TextFieldGroup";
	JLabel[] mLabels;
	JTextField[] mTextFieldGroup;
	String[] mTextFieldDataGroup;
	
	public TextFieldGroup(String[] itemStr){
		super();
		
		setLayout(null);
		setBackground(Resource.getBackgroundColor());

		if(itemStr != null && itemStr.length > 0){
			mLabels = new JLabel[itemStr.length];
			mTextFieldGroup = new JTextField[itemStr.length]; 
			for(int index = 0; index < itemStr.length; index++){
				JLabel label = new JLabel(itemStr[index]);
				JTextField textField = new JTextField();
				add(label);
				add(textField);
				mLabels[index] = label;
				mTextFieldGroup[index] = textField;
			}
		}
	}

	public void onComponentResized(){
		int width = getWidth();
		int height = getHeight();

/* doom-2015-11-2 15:1:52 
		Log.d(TAG, "onComponentResized width: "+ width);
		Log.d(TAG, "onComponentResized height: "+ height);
 doom-2015-11-2 15:1:52 */
		
		if(mLabels != null && mLabels.length > 0){

			int labelWidth = width/4;
			int labelHeigth = height/mLabels.length;
			
			for(int index = 0; index < mLabels.length; index++){
				mLabels[index].setBounds(labelWidth, labelHeigth * index, labelWidth, labelHeigth);
			}
		}
		if(mTextFieldGroup != null && mTextFieldGroup.length > 0){

			int labelWidth = width/4;
			int labelHeigth = height/mTextFieldGroup.length;
			
			for(int index = 0; index < mTextFieldGroup.length; index++){
				mTextFieldGroup[index].setBounds(labelWidth*2, labelHeigth * index, labelWidth, labelHeigth);
			}
		}
		
/* doom-2015-10-30 15:7:46 
		mCurrentOpenFileLabel.setBounds(new Rectangle(0, height - paddingBottom, infoAreaWidth, infoAreaHeight));
 doom-2015-10-30 15:7:46 */
		
	}

	public void pushDataGroup(String[] dataGroup){
		if(dataGroup != null && dataGroup.length > 0 && dataGroup.length == mTextFieldGroup.length){
			for(int index = 0; index < dataGroup.length; index++){
				mTextFieldGroup[index].setText(dataGroup[index]);
			}
		}		
	}

	public String[] pullDataGroup(){
		if(mTextFieldGroup != null && mTextFieldGroup.length > 0){
			mTextFieldDataGroup = new  String[mTextFieldGroup.length];
			for(int index = 0; index < mTextFieldGroup.length; index++){
				mTextFieldDataGroup[index] = mTextFieldGroup[index].getText();
			}		
			return mTextFieldDataGroup;
		}else{
			return null;
		}	
		
	}

}
